//
//  TestViewController.m
//  WisdomZhuHai
//
//  Created by JasonLee on 15/1/29.
//  Copyright (c) 2015年 wyd. All rights reserved.
//

#import "TestViewController.h"
#import "TopMenuMainViewController.h"
#import "PhoneVerifyViewController.h"
#import "PasswordChangeViewController.h"
#import "PersonManagerViewController.h"
#import "GuidePageViewController.h"
#import "EmptyViewController.h"
#import "ExtendTableViewController.h"
#import "PersonCouponListViewController.h"
#import "PasswordForgetViewController.h"
#import "PersonOKListViewController.h"
#import "CommonCellViewController.h"
#import "NewsCellViewController.h"
#import "CollectionListViewController.h"
#import "CollectionMenuMainViewController.h"
#import "TransforController.h"
#import "AlertMessage.h"

@interface TestViewController ()<UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate>

@property (nonatomic, strong) UITableView *test_view_table;
@property (nonatomic, strong) NSArray *test_array_section_text;
@property (nonatomic, strong) NSMutableDictionary *test_dic_row;
@property (nonatomic, assign) BOOL isLoading;

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.isLoading = false;
    [self initTestData];
    [self initTestView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void) initTestView{
    self.test_view_table = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.test_view_table.delegate = self;
    self.test_view_table.dataSource = self;
    [self.view addSubview:self.test_view_table];
}

- (void) initTestData{
    self.test_array_section_text = [NSArray arrayWithObjects:@"杂项测试",@"用户中心（登录后）",@"WebView 互调", @"引导页调整", nil];
    self.test_dic_row = [[NSMutableDictionary alloc]init];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.test_array_section_text count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:{
            NSArray *test_array_temp = [NSArray arrayWithObjects:@"接口测试",@"分类选择插件（4个参数）",@"状态栏插件测试", @"提示信息",nil];
            [self.test_dic_row setObject:test_array_temp forKey:[NSString stringWithFormat:@"%d", section]];
            return [test_array_temp count];
        }
        case 1:{
            NSArray *test_array_temp1 = [NSArray arrayWithObjects:@"帐号管理",@"找回密码",@"我的 ok 券",@"我的收藏",@"我的优惠券(新)", nil];
            [self.test_dic_row setObject:test_array_temp1 forKey:[NSString stringWithFormat:@"%d", section]];
            return [test_array_temp1 count];
        }
        case 2:
        {
            NSArray *test_array_temp2 = [NSArray arrayWithObjects:@"OC 调用 JS",@"JS 调用 OC", nil];
            [self.test_dic_row setObject:test_array_temp2 forKey:[NSString stringWithFormat:@"%d", section]];
            return [test_array_temp2 count];
        }
        case 3:{
            NSArray *test_array_temp = [NSArray arrayWithObjects:@"引导页", nil];
            [self.test_dic_row setObject:test_array_temp forKey:[NSString stringWithFormat:@"%d", section]];
            return [test_array_temp count];
        }
            
        default:
            return 0;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    NSString *string_titleOfSection = nil;
    switch (section) {
        case 0:{
            string_titleOfSection = self.test_array_section_text[section];
            break;
        }
        case 1:{
            string_titleOfSection = self.test_array_section_text[section];
            break;
        }
        case 2:{
            string_titleOfSection = self.test_array_section_text[section];
            break;
        }
        case 3:{
            string_titleOfSection = self.test_array_section_text[section];
        }
        default:
            string_titleOfSection = @"";
            break;
    }
    return string_titleOfSection;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = nil;
    NSArray *test_array_temp = [NSArray arrayWithArray:[self.test_dic_row objectForKey:[NSString stringWithFormat:@"%d", indexPath.section]]];
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"%d", indexPath.row]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = [NSString stringWithFormat:@"%@", test_array_temp[indexPath.row]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%s || indexPath:%d %d", __FUNCTION__, indexPath.section, indexPath.row);
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:{
                    [self APITestSheet];
                }
                    break;
                case 1:
                    [self gotoPageViewController];
                    break;
                case 2:
                    [self gotoBWStatusBarController];
                    break;
                case 3:
                    [self displayAlert];
                    break;
                default:
                    break;
            }
        }
            break;
        case 1:{
            switch (indexPath.row) {
                case 0:
                    [self gotoChangePassword];
                    break;
                case 1:{
                    [self gotoChangePassword2];
                }
                    break;
                case 2:{
                    [self gotoOkCouponList];
                }
                    break;
                case 3:{
                    [self gotoMyCollectionList];
                }
                    break;
                case 4:{
                    [self gotoMyCouponList];
                }
                    break;
                default:
                    break;
            }
            break;
        }
        case 2:{
            switch (indexPath.row) {
                case 0:
                    
                    break;
                    
                default:
                    break;
            }
            break;
        }
        case 3:{
            switch (indexPath.row) {
                case 0:
                    [self gotoGuideView];
                    break;
                    
                default:
                    break;
            }
            break;
        }
        default:
            break;
    }
}

- (void)APITestSheet{
    UIActionSheet *actionSheetTest = [[UIActionSheet alloc]initWithTitle:@"选择测试的接口" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"收藏列表（全部）",@"收藏列表（商家）",@"ok 券（全部）",nil];
    [actionSheetTest setTag:900005];
    [actionSheetTest dismissWithClickedButtonIndex:0 animated:YES];
    [actionSheetTest showInView:self.view];
}

-(void)displayAlert{
    AlertMessage *alert = [[AlertMessage alloc]initWithTitle:@"加载中……"];
    [alert setAlertColor:[TransforController getColorWithRGB:0x18aaf2]];
    [alert showWithCover:YES];
}

- (void)gotoPageViewController{
    TopMenuMainViewController *testViewController = [[TopMenuMainViewController alloc]init];
    testViewController.hidesBottomBarWhenPushed = YES;
    testViewController.string_title = @"测试页面1";
    testViewController.array_title = [NSArray arrayWithObjects:@"测试1",@"测试2",@"测试3",@"测试4", nil];
//    testViewController.array_page = [NSArray arrayWithObjects:@" 这是测试1",@"这是测试2",@"这是测试3", nil];
    NSMutableArray *array_temp = [[NSMutableArray alloc]init];
    for(int i = 0; i < 4; i++){
        UIViewController *instance_temp = [[UIViewController alloc]init];
        [array_temp addObject:instance_temp];
    }
    testViewController.array_page = array_temp;
    [self.navigationController pushViewController:testViewController animated:YES];
}

- (void)gotoChangePassword{
    PersonManagerViewController *testViewController = [[PersonManagerViewController alloc]init];
    testViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:testViewController animated:YES];
}

- (void)gotoChangePassword2{
    UIActionSheet *actionSheetTest = [[UIActionSheet alloc]initWithTitle:@"修改密码的方式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"通过邮箱找回",@"通过手机找回",nil];
    [actionSheetTest setTag:900002];
    [actionSheetTest dismissWithClickedButtonIndex:0 animated:YES];
    [actionSheetTest showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"%s || clickedButtonAtIndex:%d",__FUNCTION__, buttonIndex);
    if(actionSheet.tag == 900005){
        if(buttonIndex == 0){
            [[ProtocolManager shareInstance]getCollectionsWithLoginName:[ProtocolManager shareInstance].loginName andCount:10 beginNo:0 andTarget:self andSelector:@selector(APITestCallBack:)];
        }else if(buttonIndex == 1){
            [[ProtocolManager shareInstance]getCollectionWithType:@"STORE" andLoginname:[ProtocolManager shareInstance].loginName andCount:10 andBeginNo:0 andTarget:self andSelector:@selector(APITestCallBack:)];
        }else{
            [[ProtocolManager shareInstance]getOkListWithStatus:0 andPage:0 target:self selector:@selector(APITestCallBack:)];
        }
    }else{
        if(buttonIndex == 0){
            if(actionSheet.tag == 900001){
                PasswordChangeViewController *instance_passwordChange = [[PasswordChangeViewController alloc]init];
                instance_passwordChange.hidesBottomBarWhenPushed = YES;
                instance_passwordChange.isChangeWithPhone = NO;
                [self.navigationController pushViewController:instance_passwordChange animated:YES];
            }else{
                PasswordForgetViewController *instance_passwordForget = [[PasswordForgetViewController alloc]init];
                instance_passwordForget.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:instance_passwordForget animated:YES];
            }
        }else if(buttonIndex == 1){
            [self gotoChangePasswordWithPhone];
        }
    }
}

- (void)APITestCallBack:(NSDictionary *)dic{
    NSLog(@"%s || dic with api test: %@", __FUNCTION__, dic);
}

- (void)gotoChangePasswordWithPhone{
    PhoneVerifyViewController *testViewController = [[PhoneVerifyViewController alloc]init];
    testViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:testViewController animated:YES];
}

- (void)gotoOkCouponList{
    PersonOKListViewController *instance_personOkList = [[PersonOKListViewController alloc]init];
    instance_personOkList.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:instance_personOkList animated:YES];
}

- (void)gotoMyCouponList{
    
}

- (void)gotoMyCollectionList{
    CollectionMenuMainViewController *instance_topMenu = [[CollectionMenuMainViewController alloc]init];
    instance_topMenu.hidesBottomBarWhenPushed = YES;
    NSArray *array_title_temp = [NSArray arrayWithObjects:@"资讯",@"商家",@"商品",@"攻略", nil];
    NSArray *array_type_temp = [NSArray arrayWithObjects:@"NEWS", @"STORES",@"GOODS",@"STRATEGY", nil];
    instance_topMenu.string_title = @"我的收藏";
    instance_topMenu.array_title = [NSArray arrayWithArray:array_title_temp];
    instance_topMenu.isInstanceOfTableView = YES;
    NSMutableArray *array_temp = [[NSMutableArray alloc]init];
    for(int i = 0; i < 4; i++){
        CollectionListViewController *instance_collection = [[CollectionListViewController alloc]init];
        [instance_collection.view setFrame:[TransforController getRectOfView:self.view withHasNavigationBar:NO andHasBottomBar:YES]];
        instance_collection.instance_navigation = self.navigationController;
        instance_collection.target_type = array_type_temp[i];
        [instance_collection getCommentList ];
        [array_temp addObject:instance_collection];
    }
    
    instance_topMenu.array_page = array_temp;
    [self.navigationController pushViewController:instance_topMenu animated:YES];
}

- (void)gotoGuideView{
    NSArray* imgs = @[[UIImage imageNamed:@"Guide/welcome_1.jpg"], [UIImage imageNamed:@"Guide/welcome_2.jpg"], [UIImage imageNamed:@"Guide/welcome_3.jpg"]];
    EmptyViewController *guideViewCtrl = [[EmptyViewController alloc] initWithFrame:self.view.bounds];
    GuidePageViewController *instance_guideViewCtrl = [GuidePageViewController getInstance:self.view.bounds];
    [guideViewCtrl.view addSubview:instance_guideViewCtrl];
    NSMutableArray *array_temp = [[NSMutableArray alloc]init];
    for(int i = 0; i < [imgs count]; i ++){
        UIViewController *instance_view_temp = [[UIViewController alloc]init];
        [instance_view_temp.view setFrame:self.view.bounds];
        UIImageView *img_temp = [[UIImageView alloc]initWithImage:imgs[i]];
        [img_temp setFrame:instance_view_temp.view.frame];
        [instance_view_temp.view addSubview:img_temp];
        [array_temp addObject:instance_view_temp];
    }
    instance_guideViewCtrl.viewPageArray = [NSArray arrayWithArray:array_temp];
//    [instance_guideViewCtrl setView:imgs];
    [instance_guideViewCtrl initWithViews];
    guideViewCtrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:guideViewCtrl animated:YES];
}

- (void)gotoBWStatusBarController{

}

@end
